<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%app_logs}}`.
 */
class m230913_081301_create_app_logs_table extends Migration
{
    const TABLE_NAME = '{{%app_logs}}';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=MyISAM COMMENT="应用日志表格"';
        }

        $this->createTable(self::TABLE_NAME, [
            'id' => $this->primaryKey(),
            'level' => $this->string(20)->defaultValue('DEBUG')->notNull()->comment('日志等级, DEBUG、INFO、WARNING、ERROR'),
            'category' => $this->string()->defaultValue('')->notNull()->comment('种类, 例: 订单支付'),
            'prefix' => $this->text()->comment('客户端'),
            'message' => $this->text()->comment('信息'),
            'created_at' => $this->dateTime()->notNull()->comment('记录时间'),
        ], $tableOptions);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable(self::TABLE_NAME);
    }
}
